from django.shortcuts import render
from django.http import JsonResponse
from django.middleware.csrf import get_token

class index:
    @staticmethod
    def index(request):
        return render(request, 'index.html')
class config:
    def get_csrf_token(request):
        csrf_token = get_token(request)
        response = JsonResponse({'csrftoken': csrf_token})
        response.set_cookie(
            'csrftoken',
            csrf_token,
            path='/',           # 全站有效
            httponly=False,     # 允许JS读取
            samesite=None,  # 跨域时使用
            # secure=True,      # 启用HTTPS时必需
            max_age=31449600    # 1年有效期（可选）
        )
        return response
